package com.tcl.aota.admin.job;

import com.tcl.aota.admin.dto.FileDTO;
import com.tcl.aota.admin.manager.Amazons3Manager;
import com.tcl.aota.common.constants.Constants;
import org.apache.log4j.Logger;

/**
 * @author kelong
 * @date 11/21/14
 */
public class FileTask implements Runnable {
    Logger LOG = Logger.getLogger(FileTask.class);
    private Amazons3Manager amazons3Manager;
    private FileDTO fileDTO;

    public FileTask(Amazons3Manager amazons3Manager, FileDTO fileDTO) {
        this.amazons3Manager = amazons3Manager;
        this.fileDTO = fileDTO;
    }

    public void run() {
        try {
            if (fileDTO == null) {
                return;
            }
            int flag = fileDTO.getFlag();
            LOG.info("task start..." + flag + "," + fileDTO.getDescPath());
            switch (flag) {
                case Constants.AMAZON.UPLOAD_FLAG:
                    amazons3Manager.copy(fileDTO);
                    break;
                case Constants.AMAZON.DELETE_FLAG:
                    amazons3Manager.deleteFile(fileDTO.getDescPath());
                    break;
                default:
                    break;
            }
            LOG.info("task end...");
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}
